/**
 * 
 */
package com.cea.papyrus.diagram.usecase.editpart;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import com.cea.papyrus.core.editpart.GraphNodeEditPart;
import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.Property;

/**
 * Override to provides specific setting.
 * 
 * @author dumoulin
 * 
 */
public class ExtensionPointListEditPartListener extends com.cea.papyrus.core.listener.GraphElementListener {

    /**
     * this class create a listener on the umlElement.
     * 
     * @param editPart
     *            the editpart of the UMLElement
     */
    public ExtensionPointListEditPartListener(AbstractGraphicalEditPart editPart) {
        super(editPart);
    }

    /**
     * Notify changed.
     * 
     * @param notification
     *            the notification
     * 
     * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
     */
    public void notifyChanged(Notification notification) {
        // EditPart parent =umlEditPart.getParent();
        Debug.debug(this, "Notification GE = " + notification, channel);
        // Refresh the element
        if (notification.getEventType() != Notification.REMOVING_ADAPTER) {
            editPart.refresh();

            // Default case
            ((GraphNodeEditPart) editPart).getModelManager().modifGraphElement(((GraphNodeEditPart) editPart).getGraphNode());

            // Change graph node appearance
            if ((notification.getEventType() == Notification.SET) && (notification.getNotifier() instanceof Property)) {
                Property aProperty = (Property) notification.getNotifier();
                if (aProperty.getKey().equals(NodeHelper.NODE_FIGURE_APPEARANCE)) {
                    Debug.debug(this, "CHANGE " + NodeHelper.NODE_FIGURE_APPEARANCE, channel);
                    if (editPart instanceof GraphNodeEditPart) {
                        ((GraphNodeEditPart) editPart).changeEditPartFigure();
                    }
                }
            }

            // New extension point in a use case
            if (editPart instanceof ExtensionPointListEditPart && (notification.getEventType() == Notification.ADD || notification.getEventType() == Notification.REMOVE)) {
                Debug.debug(this, "MODIFY " + NodeHelper.NODE_FIGURE_APPEARANCE, channel);
                ((UseCaseEditPart) editPart.getParent()).modifyEllipseFormAppearance();
            }
        }
    }
}
